package com.jxgyl.gateway.filter;

import com.jxgyl.gateway.config.UrlConfig;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

/**
 * @program: middleplatform
 * @description: 自定义过滤器，需要把spring.cloud.gateway.discovery.locator.enabled=false，才会生效
 * @author: Wanglipeng
 * @create: 2022-01-21 15:21
 **/
@Component
@Log4j2
public class UrlFilterFactory extends AbstractGatewayFilterFactory implements Ordered {
    @Autowired
    UrlFilter urlFilter;

    @Override
    public GatewayFilter apply(Object config) {
        /*两种方式都可以，目前测试使用
        return ((exchange, chain) -> {
            log.info("urlFilter_test");
            log.info("urlConfig="+urlConfig.getInterceptUrls());
            return chain.filter(exchange);
        });*/
        return urlFilter;
    }

    @Override
    public int getOrder() {
        return 3;
    }
}
